//
//  SGGeoModel.swift
//  songguo
//
//  Created by 潘传洲 on 16/6/11.
//  Copyright © 2016年 pcz. All rights reserved.
//


import UIKit
/**
 *  所在城市
 */
struct City {
    var name : String?
    var longitude : Double?
    var latitude: Double?
    
    init(cityDict : [String : AnyObject]) {
        self.name = cityDict["name"] as? String
        self.longitude = cityDict["longitude"] as? Double
        self.latitude = cityDict["latitude"] as? Double
    }
    
}

/**
 *  具体经纬度
 */
struct Coordinates {
    var longitude : Double?
    var latitude: Double?
    
    init(coordinatesDict : [String : AnyObject]) {
        self.longitude = coordinatesDict["longitude"] as? Double
        self.latitude = coordinatesDict["latitude"] as? Double
    }
}

/// 地理位置模型
class SGGeoModel: NSObject {

    var name: String?
    var address: String?
    
    var city : City?
    var coordinates : Coordinates?
    
    
    class func initWithDict(dict : [String : AnyObject]) -> SGGeoModel {
        
        let geo = SGGeoModel()
        geo.name = dict["name"] as? String
        geo.address = dict["address"] as? String
        let city = dict["city"] as? [String : AnyObject]
        let coordinates = dict["coordinates"] as? [String: AnyObject]
        geo.city = City(cityDict: city!)
        geo.coordinates = Coordinates(coordinatesDict: coordinates!)
        return geo
    }
    
}
